<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增预报间隔维护')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        .success{
            color: greenyellow;
        }
        .error{
            color: orangered;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-forecastInterval-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required>
                <span class="name"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">缩写：</label>
            <div class="col-sm-8">
                <input name="code" class="form-control" type="text" required>
                <span class="code"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input name="sortOrder" class="form-control" type="text" required>
                <span class="sortOrder">数字越大排的越前面,范围0-999</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "product/forecastInterval"
    $("#form-forecastInterval-add").validate({
        focusCleanup: true
    });

    //内容校验
    var intervalName = code = order = 0;
    $("input[name=name]").on('change',function () {
        var text = $("input[name=name]").val();
        var names = [[${names}]];
        if ($.common.isEmpty(text)){
            $(".name").addClass('error').removeClass('success').html("请填写显示名");intervalName = 0;
        }else if (names.includes(text)){
            $(".name").addClass('error').removeClass('success').html("该值不可用，系统中已存在！");intervalName = 0;
        }else {
            $(".name").addClass('success').removeClass('error').html("验证通过");intervalName = 1;
        }
    })
    $("input[name=code]").on('change',function () {
        var text = $("input[name=code]").val();
        var codes = [[${codes}]];
        if ($.common.isEmpty(text)){
            $(".code").addClass('error').removeClass('success').html("请填写编号");code = 0;
        }else if (codes.includes(text)){
            $(".code").addClass('error').removeClass('success').html("该值不可用，系统中已存在！");code = 0;
        }else {
            $(".code").addClass('success').removeClass('error').html("验证通过");code = 1;
        }
    })
    $("input[name=sortOrder]").on("change",function () {
        var text = $("input[name=sortOrder]").val();
        var reg = /^[0-9][0-9]{0,2}$/;
        var flag = reg.test(text);
        if (flag){
            $(".sortOrder").removeClass('error').addClass('success').html("验证通过");order = 1;
        }else {
            $('.sortOrder').addClass('error').removeClass('success').html("请填写排序,范围0-999");order = 0;
        }
    })

    function submitHandler() {
        if (intervalName != 1 || code != 1 || order != 1){return;}
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-forecastInterval-add').serialize());
        }
    }

    $("input[name='createDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='updateDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>
